﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Classes.EasterEggs {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Interfaces.*;
    import flash.display.*;
    import flash.geom.*;
    import com.greensock.*;
    import flash.text.*;
    import flash.net.*;
    import com.greensock.easing.*;

    public class CreditsEasterEgg implements IEasterEgg {

        private static const TEXT_WIDTH:Number = 500;
        private static const TEXT_HEIGHT:Number = 340;

        public function get code():String{
            return ("credits");
        }
        public function execute():void{
            var _local1:URLLoader = new URLLoader();
            _local1.addEventListener(Event.COMPLETE, this.onCreditsLoadComplete);
            _local1.load(new URLRequest((Config.BASE_PATH + "credits.txt")));
        }
        private function onCreditsLoadComplete(_arg1:Event):void{
            var credits:* = null;
            var event:* = _arg1;
            var position:* = new Point(((GlobalEngine.stage.stageWidth / 2) - (TEXT_WIDTH / 2)), ((GlobalEngine.stage.stageHeight / 2) - (TEXT_HEIGHT / 2)));
            var textFormat:* = GlobalEngine.fontMapper.mapTextFormat("Credits", new TextFormat(FontNames.UNSTYLED_UI_FONT, 24, 0xFFFFFF, false));
            textFormat.align = TextFormatAlign.CENTER;
            textFormat.leftMargin = 5;
            textFormat.rightMargin = 5;
            var creditsText:* = new TextField();
            creditsText.defaultTextFormat = textFormat;
            creditsText.selectable = false;
            creditsText.x = position.x;
            creditsText.y = position.y;
            creditsText.wordWrap = true;
            creditsText.multiline = true;
            creditsText.htmlText = (URLLoader(event.currentTarget).data as String);
            creditsText.width = TEXT_WIDTH;
            creditsText.height = (24 * creditsText.numLines);
            var bitmapData:* = new BitmapData(creditsText.width, creditsText.height, true, 0);
            bitmapData.draw(creditsText);
            var bitmap:* = new Bitmap(bitmapData);
            credits = new Sprite();
            var background:* = new Sprite();
            credits.addChild(background);
            background.graphics.beginFill(0, 0.5);
            background.graphics.drawRoundRect(0, 0, TEXT_WIDTH, TEXT_HEIGHT, 20, 20);
            background.graphics.endFill();
            credits.addChild(bitmap);
            credits.x = position.x;
            credits.y = position.y;
            var mask:* = new Sprite();
            mask.x = position.x;
            mask.y = position.y;
            mask.graphics.beginFill(0xFFFFFF, 1);
            mask.graphics.drawRect(0, 0, TEXT_WIDTH, TEXT_HEIGHT);
            mask.graphics.endFill();
            credits.mask = mask;
            GlobalEngine.stage.addChild(credits);
            TweenLite.to(bitmap, (creditsText.numLines * 0.75), {
                y:((((-1 * creditsText.height) + TEXT_HEIGHT) + position.y) - 10),
                ease:Linear.easeNone,
                delay:3,
                onComplete:function ():void{
                    if (credits != null){
                        GlobalEngine.stage.removeChild(credits);
                        credits = null;
                    };
                }
            });
        }

    }
}//package Engine.Classes.EasterEggs 
